package String;

import java.util.Scanner;

public class money_change {
    public static void main(String[] args) {
        //键盘输入金额，转换成中文大写
        Scanner sc = new Scanner(System.in);
        int money;
        //确认输入金额有效
        while (true) {

            System.out.print("Enter money: ");
            money = sc.nextInt();
            if(money>=0&&money<=99999999){
                break;

            }
            else{
                System.out.println("Invalid input");
            }

        }

        String moneyStr="";
        //得到money的每一位数字
        while(true){
            int ge=money%10;
          String capitalNum=  getCapitalNumber(ge);
          moneyStr=capitalNum+moneyStr;//注意顺序，capitalNum在前面
            //第一次：”壹“；第二次：”貮“+”壹“，”貮壹“
            money=money/10;
            if(money==0){
                break;
            }
        }

        //在前面补零，补齐七位
        int count=7-moneyStr.length();
        for(int i=0;i<count;i++){
            moneyStr="零"+moneyStr;
        }
        System.out.println(moneyStr);

        //插入单位
        String []arr={"佰","拾","万","仟","佰","拾","元"};
                for(int i=0;i<moneyStr.length();i++){
                    //打印数字
                    System.out.print(moneyStr.charAt(i));
                    //插入单位
                    System.out.print(arr[i]);
                }
    }


    //数字变大写中文
    public static String getCapitalNumber(int number) {
        String []arr={"零","壹","貮","叁","肆","伍","陆","柒","捌","玖"};
        return arr[number];
    }
}
